package com.letfox.test.example;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.commons.collections.map.HashedMap;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import com.letfox.statistical.dao.MediaStatisticDao;
import com.letfox.statistical.dao.GeoStatisticDao;
import com.letfox.statistical.enums.UDMDelEnums;
import com.letfox.statistical.model.UDMDeviceStatistic;
import com.letfox.statistical.model.UDMMediaStatistic;
import com.letfox.statistical.model.UDMGeoStatistic;
import com.letfox.test.util.DateUtil;
import com.letfox.test.util.MyBatisUtil;


/**
* 单元测试
*/
public class MediaStatisticExample {


	/**
	 * 需要单元测试的时候在取消注释
	 */
	private MediaStatisticDao mediaStatisticDao;
	@Test
	public void add_MediaStatistic(){
		
		try {
			SqlSession session = MyBatisUtil.getSqlSession(true);
			UDMMediaStatistic mediaStatistic = new UDMMediaStatistic();
			mediaStatistic.setUdmAdMediaId("00222");
			mediaStatistic.setAdPlanId("001222");
			mediaStatistic.setMedia("DVD");
			mediaStatistic.setPlayTime(new Date());
			mediaStatistic.setShowTimes(1);
			mediaStatistic.setClickTimes(1);
			mediaStatistic.setDownloadTimes(1);
			mediaStatistic.setAmount(new BigDecimal("33333.54"));
			mediaStatistic.setCreateTime(new Date());
			mediaStatistic.setUpdateTime(new Date());
			mediaStatistic.setCreateBy("admin");
			mediaStatistic.setUpdateBy("user");
			mediaStatistic.setDel(UDMDelEnums.UDMDel.EFFECTIVE.getValue());
			
			mediaStatisticDao = session.getMapper(MediaStatisticDao.class);
			mediaStatisticDao.insert(mediaStatistic);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	@Test
	public void DeviceStatistic_update_Test(){
		
		try {
			SqlSession session = MyBatisUtil.getSqlSession(true);

			UDMMediaStatistic mediaStatistic = new UDMMediaStatistic();
			mediaStatistic.setUdmAdMediaId("00222");
			mediaStatistic.setAdPlanId("001222");
			mediaStatistic.setMedia("RAM");
			mediaStatistic.setPlayTime(new Date());
			mediaStatistic.setShowTimes(1);
			mediaStatistic.setClickTimes(1);
			mediaStatistic.setDownloadTimes(1);
			mediaStatistic.setAmount(new BigDecimal("33333.54"));
			mediaStatistic.setCreateTime(new Date());
			mediaStatistic.setUpdateTime(new Date());
			mediaStatistic.setCreateBy("admin");
			mediaStatistic.setUpdateBy("user");
			mediaStatistic.setDel(UDMDelEnums.UDMDel.EFFECTIVE.getValue());
			
			mediaStatisticDao = session.getMapper(MediaStatisticDao.class);
			int i = mediaStatisticDao.update(mediaStatistic);
			System.out.println(i+"-----------------------------------");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	
	
	@Test
	public void DeviceStatistic_select_Test(){
		
		try {
			SqlSession session = MyBatisUtil.getSqlSession(true);
			UDMDeviceStatistic DeviceStatistic = new UDMDeviceStatistic();
			
			Map map = new HashedMap();

			map.put("adPutintoId", "001222");
			map.put("media", "DVD");
			map.put("startTime", DateUtil.strToDateSql("2018-03-17 18:00:00"));
			map.put("endTime", DateUtil.strToDateSql("2018-03-19 18:00:00"));
			
			
			mediaStatisticDao = session.getMapper(MediaStatisticDao.class);
			List<UDMDeviceStatistic>  DeviceStatistics= mediaStatisticDao. getList(map);
			System.out.println(DeviceStatistics.size()+"-----------------------------------");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
